---
category: Validator
created: '2021-10-22'
title: Check if a character is a digit
---

**JavaScript version**

```js isDigit.js
const isDigit = (char) => char < 10;

// Or
const isDigit = (char) => char.length === 1 && c >= '0' && c <= '9';

// Or
const isDigit = (char) => Boolean([true, true, true, true, true, true, true, true, true, true][char]);
```

**TypeScript version**

```ts isDigit.ts
const isDigit = (char: string): boolean => char < 10;

// Or
const isDigit = (char: string): boolean => char.length === 1 && c >= '0' && c <= '9';

// Or
const isDigit = (char: string): boolean => Boolean([true, true, true, true, true, true, true, true, true, true][char]);
```

**Examples**

```js examples.js
isDigit('a'); // false
isDigit('abc'); // false
isDigit(10); // false
isDigit('10'); // false

isDigit('2'); // true
isDigit(2); // true
```
